package com.zpb.admin.controller;


import com.zpb.framework.domain.ApiResult;
import com.zpb.framework.domain.dto.RoleAddDto;
import com.zpb.framework.domain.dto.RoleChangeStatusDto;
import com.zpb.framework.domain.dto.RoleQueryDto;
import com.zpb.framework.domain.dto.RoleUpdateDto;
import com.zpb.framework.domain.enums.ResultCodeEnum;
import com.zpb.framework.domain.vo.PageVo;
import com.zpb.framework.domain.vo.RoleVo;
import com.zpb.framework.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description:
 * @Author: zhaopengbo
 * @Date: 2025/9/22
 */
@RestController
@RequestMapping("/system/role")
public class SysRoleController {
    @Autowired
    private RoleService roleService;
    @GetMapping("/list")
    public ApiResult<PageVo> getList(@RequestParam Integer pageNum,
                                     @RequestParam Integer pageSize,
                                     RoleQueryDto query) {
        return roleService.getRoleList(pageNum,pageSize,query);
    }
    @PutMapping("/changeStatus")
    public ApiResult changeStatus(@RequestBody RoleChangeStatusDto roleChangeStatusDto) {

        return roleService.changeStatus(roleChangeStatusDto);
    }
    @PostMapping
    public ApiResult addRole(@RequestBody RoleAddDto roleAddDto) {
        if (roleAddDto == null) {
            return ApiResult.failure(ResultCodeEnum.MISS_PARAM);
        }
        if (roleAddDto.getRoleName() == null || roleAddDto.getMenuIds() == null) {
            return ApiResult.failure(ResultCodeEnum.MISS_PARAM);
        }
        return roleService.addRole(roleAddDto);
    }
    @GetMapping("/{id}")
    public ApiResult<RoleVo> getRole(@PathVariable Long id) {
        return roleService.getRoleById(id);
    }
    @PutMapping
    public ApiResult updateRole(@RequestBody RoleUpdateDto roleUpdateDto) {
        return roleService.updateRole(roleUpdateDto);
    }
    @GetMapping("listAllRole")
    public ApiResult<List<RoleVo>> getAllRoleList() {
        return roleService.getAllRoleList();
    }
}
